package cn.tedu.micro.demo.all.dao.repository;

import cn.tedu.micro.demo.all.dao.mapper.CartMapper;
import cn.tedu.micro.demo.pojo.po.CartPO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;

@Repository
public class CartRepositoryImpl implements CartRepository{
    @Autowired
    private CartMapper cartMapper;

    @Override
    public void save(CartPO cartPO) {

        System.out.println("cartmapper实现类："+cartMapper.getClass().getMethods());
        cartMapper.insert(cartPO);
    }

    @Override
    public List<CartPO> findByUserId(String userId) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("user_id",userId);
        List<CartPO> cartPOList = cartMapper.selectList(queryWrapper);
        return cartPOList;
    }

    @Override
    public int deleteByUserIdAndProductCode(String userId, String productCode) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("user_id",userId);
        queryWrapper.eq("product_code",productCode);
        int dn = cartMapper.delete(queryWrapper);


        return dn;
    }
}
